package com.jz.netthings.analysis.controller;


import com.jz.netthings.analysis.bean.ProviderRound;
import com.jz.netthings.analysis.service.ProviderRoundBaseService;
import com.jz.netthings.analysis.service.ProviderRoundService;
import com.jz.netthings.analysis.service.RoundsBaseService;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.utils.AdscmDateUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Wrapper;
import java.util.Date;

/**
 * <p>
 * 供浆者轮次 前端控制器
 * </p>
 *
 * @author yangyunyun
 * @since 2019-07-16
 */
@RestController
@RequestMapping("/adscm/analysis/providerRound")
public class ProviderRoundController {

    @Autowired
    ProviderRoundBaseService providerRoundBaseService;
    @Autowired
    ProviderRoundService providerRoundService;
    @Autowired
    RoundsBaseService roundsBaseService;

    /**
     * 构造供浆者轮次表的基础统计数据
     * @param providerId
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadProviderRoundBase")
    public SimpleCoreResponse loadProviderRoundBase(Long providerId) throws AdscmSystemException {

        if (providerId == null){
            providerRoundBaseService.loadAllProviderRoundBase();
        }else {
            providerRoundBaseService.loadRoundBase(providerId);
        }

        return new SimpleCoreResponse("200", "执行成功", null);
    }

    /**
     * 构造轮次标准时间表的基本数据
     * @param year
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadRoundBase")
    public SimpleCoreResponse loadRoundBase(int year) throws AdscmSystemException {

        roundsBaseService.loadRoundsBaseByYear(year);
        return new SimpleCoreResponse("200", "执行成功", null);
    }

    /**
     * 构造某个供浆者某一年的所有轮次数据
     * @param providerId
     * @param year
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadProviderRound")
    public SimpleCoreResponse loadProviderRound(Long providerId,int year) throws AdscmSystemException {

        ProviderRound round = providerRoundService.loadProviderRound(providerId,year);
        return new SimpleCoreResponse("200", "执行成功", round);
    }
    /**
     * 构造所有供浆者某一年的所有轮次数据
     * @param year
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadAllProviderRound")
    public SimpleCoreResponse loadAllProviderRound(int year) throws AdscmSystemException {
        providerRoundService.loadProviderRound(year);
        return new SimpleCoreResponse("200", "执行成功", null);
    }
    /**
     * 构造某一天登记的供浆者当轮的数据
     * @param regDate
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadRegProviderRound")
    public SimpleCoreResponse loadRegProviderRound(String regDate) throws AdscmSystemException {
        providerRoundService.loadRegProviderRound(regDate);
        return new SimpleCoreResponse("200", "执行成功", null);
    }

    /**
     * 获取当前轮次
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getCurrentRound")
    public SimpleCoreResponse getCurrentRound() throws AdscmSystemException {

        String date = AdscmDateUtils.getNowOnlyDateFomat1(new Date());

        return new SimpleCoreResponse("200", "查询成功", roundsBaseService.selectRoundsByDate(date));
    }

}

